﻿<ResourceDictionary
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

  xmlns:d="clr-namespace:System.Windows.Data;assembly=PresentationFramework"
  xmlns:cm="clr-namespace:System.ComponentModel;assembly=WindowsBase"

  xmlns:controls="clr-namespace:MiniUML.View.Controls;assembly=MiniUML.View"
  xmlns:shapes="clr-namespace:MiniUML.Plugins.UmlClassDiagram.Controls.View.Shapes"
  xmlns:designItem="clr-namespace:MiniUML.View.Views.ResizeAdorner;assembly=MiniUML.View"

  xmlns:connect="clr-namespace:MiniUML.Plugins.UmlClassDiagram.Controls.View.Connect"

  xmlns:conv="clr-namespace:MiniUML.Plugins.UmlClassDiagram.Converter"
  xmlns:viewconv="clr-namespace:MiniUML.View.Converter;assembly=MiniUML.View"
  >
  <ResourceDictionary.MergedDictionaries>
    <ResourceDictionary Source="/MiniUML.Plugins.UmlClassDiagram;component/Themes/Brushes.xaml"  />

    <ResourceDictionary Source="/MiniUML.Plugins.UmlClassDiagram;component/Themes/UmlTextBox.xaml"  />
  </ResourceDictionary.MergedDictionaries>

  <Style TargetType="{x:Type shapes:UmlNodeShape}">
    <Setter Property="SnapsToDevicePixels" Value="True"/>
    <Setter Property="Width" Value="{Binding Width}" />
    <Setter Property="Height" Value="{Binding Height}" />
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type shapes:UmlNodeShape}">

          <designItem:DesignerItem IsSelected="{Binding Path=IsSelected}"
                                   ResizeSelectedShapes="{Binding ResizeSelectedShapesCommand}"
                                   Background="{x:Null}" ><!-- Background=null makes inner part hittest invisible -->
            <designItem:DesignerItem.Content>

              <!-- Border Background="{StaticResource ItemBrush}"
                  BorderBrush="{TemplateBinding Property=BorderBrush}"
                  BorderThickness="{TemplateBinding Property=BorderThickness}" 
              -->
                <Grid VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
                  <Grid.Resources>
                    <BooleanToVisibilityConverter x:Key="boolToVisConverter" />
                    <conv:EmptyStringToNullConverter x:Key="emptystringToNullConverter" />
                    <conv:EmptyStringToVisibilityConverter x:Key="emptystringToVisibilityConverter" />
                    <conv:StringBoolToVisibilityConverter x:Key="boolToVisibilityConverter" />
                  </Grid.Resources>

                  <!-- Node in Deployment Diagram
                       ===> Some base points of the controls 3D Box are computed in dependence of ActualWidth and ActualHeight
                            These base point computation is realized through control bindings to its control instance -->
                  <Path Stroke="Black" Fill="White" StrokeThickness="1" StrokeLineJoin="Round">
                    <Path.Data>
                      <PathGeometry>
                        <PathGeometry.Figures>
                          <PathFigureCollection>
                            <PathFigure IsClosed="True" StartPoint="20,1">
                              <PathFigure.Segments>
                                <PathSegmentCollection>
                                  <LineSegment Point="{Binding Path=P2_SecondSquare, RelativeSource={RelativeSource AncestorType={x:Type shapes:UmlNodeShape}}}" />
                                  <LineSegment Point="{Binding Path=P2_FirstSquare, RelativeSource={RelativeSource AncestorType={x:Type shapes:UmlNodeShape}}}" />
                                  <LineSegment Point="1,20" />
                                </PathSegmentCollection>
                              </PathFigure.Segments>
                            </PathFigure>

                            <PathFigure IsClosed="True" StartPoint="{Binding Path=P2_SecondSquare, RelativeSource={RelativeSource AncestorType={x:Type shapes:UmlNodeShape}}}">
                              <PathFigure.Segments>
                                <PathSegmentCollection>
                                  <LineSegment Point="{Binding Path=P3_SecondSquare, RelativeSource={RelativeSource AncestorType={x:Type shapes:UmlNodeShape}}}" />
                                  <LineSegment Point="{Binding Path=P4_FirstSquare, RelativeSource={RelativeSource AncestorType={x:Type shapes:UmlNodeShape}}}" />
                                  <LineSegment Point="{Binding Path=P2_FirstSquare, RelativeSource={RelativeSource AncestorType={x:Type shapes:UmlNodeShape}}}" />
                                </PathSegmentCollection>
                              </PathFigure.Segments>
                            </PathFigure>

                            <PathFigure IsClosed="True" StartPoint="1,20" >
                              <PathFigure.Segments>
                                <PathSegmentCollection>
                                  <LineSegment Point="{Binding Path=P2_FirstSquare, RelativeSource={RelativeSource AncestorType={x:Type shapes:UmlNodeShape}}}" />
                                  <LineSegment Point="{Binding Path=P4_FirstSquare, RelativeSource={RelativeSource AncestorType={x:Type shapes:UmlNodeShape}}}" />
                                  <LineSegment Point="{Binding Path=P3_FirstSquare, RelativeSource={RelativeSource AncestorType={x:Type shapes:UmlNodeShape}}}" />
                                </PathSegmentCollection>
                              </PathFigure.Segments>
                            </PathFigure>
                          </PathFigureCollection>
                        </PathGeometry.Figures>
                      </PathGeometry>
                    </Path.Data>
                  </Path>

                  <StackPanel Grid.Column="0" Grid.Row="0" Orientation="Vertical" Margin="5,25,25,5">
                    <TextBox BorderThickness="0"
                             FontFamily="Consola"
                             Margin="3,3,3,0"
                             Visibility="{Binding Path=Stereotype, Converter={StaticResource emptystringToVisibilityConverter}}"
                             Background="Transparent"
                             Foreground="Black"
                             IsTabStop="False"
                             Style="{StaticResource UmlTextBox}"
                             Text="{Binding Path=Stereotype}"
                             AcceptsReturn="False"
                             HorizontalAlignment="Center" VerticalAlignment="Bottom"
                           />

                    <TextBox BorderThickness="0"
                             FontFamily="Consola"
                             Margin="3,0,3,3"
                             Background="Transparent"
                             Foreground="Black"
                             IsTabStop="False"
                             Style="{StaticResource UmlTextBox}"
                             Text="{Binding Path=Name}"
                             AcceptsReturn="False"
                             HorizontalAlignment="Center" VerticalAlignment="Top"
                           />
                  </StackPanel>

                  <Image Source="{Binding Path=ShapeImageUrl,Converter={StaticResource emptystringToNullConverter}}"                      
                         Visibility="{Binding Path=ShapeImageUrl, Converter={StaticResource emptystringToVisibilityConverter}}"
                         Grid.Column="1" Grid.Row="0"
                         HorizontalAlignment="Center"
                         VerticalAlignment="Center"
                         Margin="3"/>

                </Grid>
              <!-- /Border -->

            </designItem:DesignerItem.Content>
          </designItem:DesignerItem>

          <ControlTemplate.Triggers>
            <Trigger Property="IsMouseOver" Value="True">
              <Setter Property="Cursor" Value="Hand"/>
            </Trigger>
          </ControlTemplate.Triggers>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>

</ResourceDictionary>
